home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1029 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.9 KB  |  73 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: static members as members of a metacla
  5. Date: 10 Apr 1996 09:56:40 PDT
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4kgjh3$qd6@engnews1.Eng.Sun.COM>
  9. References: <316BC211.1B39@trcinc.com>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 10 Apr 1996 15:18:59 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMWvoSUy4NqrwXLNJAQGh9wH+J4yjdWiZWCfxjm6DGlIX9FRQsSyGo2cu
  15.     1bMugVW782cs81B2UZLY7JidnYST0n5RwLrqRhMjGowT2Ix+AezhqA==
  16.     =iYx0
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article 1B39@trcinc.com, Rich Paul <rpaul@trcinc.com> writes:
  20. >Jeffrey C. Gealow wrote:
  21. >> 
  22. >> In article <4jckdc$ad6@engnews1.Eng.Sun.COM> clamage@Eng.Sun.COM
  23. >> (Steve Clamage) writes:
  24. >> 
  25. >>    I believe a reasonable solution to the problem of initialization of
  26. >>    non-local static data is not to use non-local static data!
  27. >> 
  28. >>    Instead of a static data object or static class data member, use a
  29. >>    function with a local static object.
  30. >> 
  31. >> But this adds the overhead of the function call mechanism to every use
  32. >> of the object.
  33. >> 
  34. >
  35. >If you inline the function, are you guarenteed a 
  36. >single instance, or might there be one in each 
  37. >compilation unit, or in each invocation of the 
  38. >function?
  39.  
  40. The ARM was vague on that point, and compilers have differed in their
  41. behavior. On the one hand, inline functions are supposed to have the
  42. semantics of static functions, meaning a separate copy of the function
  43. (and of its static variables) in each translation unit where it is used.
  44. On the other hand, it cannot be the case that a class member function
  45. exists in several copies; that would violate the One-Definition Rule.
  46.  
  47. The latest draft standard allows for both internal and external linkage of
  48. inline functions.
  49.  
  50. All class member functions have external linkage, meaning the program
  51. behaves as if only one copy of the function exists in the program.
  52.  
  53. A non-member function may be declared "extern inline":
  54.     extern inline T& Tobject() { static T t; return t; }
  55. This example means the program behaves as if only one copy of the function
  56. exists, including any local static data. It is up to the compiler to
  57. figure out how to arrange for that to happen.
  58.  
  59. A non-member inline function has internal linkage (behaves like an ordinary
  60. static function) if it is not declared "extern".
  61.  
  62. I don't think any compilers support this new set of rules yet, but eventually
  63. all compilers will.
  64. ---
  65. Steve Clamage, stephen.clamage@eng.sun.com
  66. ---
  67. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  68.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  69.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  70.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  71.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  72. ]
  73.